// 源插件
import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import router from 'umi/router';

// 视图插件
import {
  Spin,
  Row,
  Col,
  Card,
  Form,
  Input,
  Select,
  Icon,
  Button,
  Dropdown,
  Menu,
  InputNumber,
  DatePicker,
  Modal,
  message,
  Badge,
  Divider,
  Steps,
  Radio,
  Upload,
} from 'antd';

// 外部组件
import StandardTable from '@/components/StandardTable';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';

// css OR less预编译器

// 图片

const FormItem = Form.Item;

/**
 *  Created by xjc on 2019/8/15
 *  Describe:数据连接
 */

@connect(({ riskoption, loading }) => ({
  riskoption,
  loading: loading.models.riskControlRule,
}))
@Form.create()
class RiskDetail extends PureComponent {
  componentWillMount() {}

  /**
   *  Created by xjc on 2019/8/15
   *  Describe:当前状态
   */

  state = {};

  onChange = e => {};

  okHandle() {
    this.props.form.validateFields((err, values) => {
      if (!err) {
        const { dispatch } = this.props;
        dispatch({
          type: 'riskoption/ChangeRiskData',
          payload: {
            id: values.id,
            trade: values.trade,
            risklevel: parseInt(values.risklevel),
            mark: values.mark,
          },
          callback: res => {
            if (res.code === 1) {
              message.success(res.message);
              this.props.closeRecord();
            } else {
              message.warning(res.message);
            }
          },
        });
      }
    });
  }

  cancelHandle() {
    this.props.closeRecord();
  }

  render() {
    const {} = this.state;
    const { record, form, RiskDetailVisible } = this.props;
    const { getFieldDecorator } = form;

    return (
      <Modal
        destroyOnClose
        title="风控条目修改"
        visible={RiskDetailVisible}
        centered
        onOk={this.okHandle.bind(this)}
        onCancel={this.cancelHandle.bind(this)}
      >
        <Form onSubmit={this.handleSearch} style={{ overflowY: 'scroll' }}>
          <FormItem label="ID" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('id', { initialValue: record.id })(
              <Input readOnly style={{ width: '85%' }} placeholder="ID" />
            )}
          </FormItem>

          <FormItem label="期权代码" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('name', { initialValue: record.name })(
              <Input readOnly style={{ width: '85%' }} placeholder="期权代码" />
            )}
          </FormItem>

          <FormItem label="风险等级标记" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('risklevel', { initialValue: `${record.risklevel}` })(
              <Select style={{ width: '85%' }}>
                <Option key={3}>高级</Option>
                <Option key={2}>中级</Option>
                <Option key={1}>低级</Option>
              </Select>
            )}
          </FormItem>

          <FormItem label="所属行业" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('trade', { initialValue: record.trade })(
              <Input style={{ width: '85%' }} placeholder="所属行业" />
            )}
          </FormItem>

          <FormItem label="事件备注" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('mark', { initialValue: record.mark })(
              <Input.TextArea style={{ width: '85%', height: '88px' }} placeholder="事件备注" />
            )}
          </FormItem>
        </Form>
      </Modal>
    );
  }

  componentDidMount() {}

  componentWillUnmount() {}
}

export default RiskDetail;
